package com.sun.designpatternsdemo.factory

import android.os.Bundle
import androidx.databinding.DataBindingUtil
import com.sun.designpatternsdemo.base.BaseActivity
import com.sun.designpatternsdemo.R
import com.sun.designpatternsdemo.app.AppConstant
import com.sun.designpatternsdemo.app.EMTagHandler
import com.sun.designpatternsdemo.databinding.ActivityFactoryBinding
import com.sun.designpatternsdemo.factory.bean.cxgc.XianRoujiamoTeSeStrore
import com.sun.designpatternsdemo.factory.bean.cxgc.XianSimpleRoujiaMoTeSeFacktory
import com.sun.designpatternsdemo.factory.bean.gcff.XianRoujiamoStaore
import com.sun.designpatternsdemo.factory.bean.gcff.XianSimpleRoujiamoFactory
import com.sun.designpatternsdemo.factory.bean.jdgc.RoujiamoStore
import com.sun.designpatternsdemo.factory.bean.jdgc.SimpleRoujiaMoFactory
/**
 * 版权：xx公司 版权所有
 * @author sun
 * 版本：1.0
 * 创建日期：${DATE} ${TIME}
 * 描述：${DATA}
 * * 今天继续设计模式之旅，给大家带来工厂模式，简单列一下这个模式的家族：
 * 1、静态工厂模式
 * 2、简单工厂模式
 * 3、工厂方法模式
 * 4、抽象工厂模式
 * <p>
 * <p>
 * 1、静态工厂模式
 * 这个最常见了，项目中的辅助类，TextUtil.isEmpty等，类+静态方法。下面开始详细介绍：略
 */
class FactoryActivity : BaseActivity<ActivityFactoryBinding>() {

    override fun layoutId(): Int = R.layout.activity_factory

    override fun initView(savedInstanceState: Bundle?) {
        mDataBind = DataBindingUtil.setContentView(this, R.layout.activity_factory)
        title = "工厂模式"
        mDataBind.apply {
            tvDefine.text = EMTagHandler.fromHtml(AppConstant.JDGC_FACTORY_DEFINE)
            tvDefine2.text = EMTagHandler.fromHtml(AppConstant.GCFF_FACTORY_DEFINE)
            tvDefine3.text = EMTagHandler.fromHtml(AppConstant.CXGC_FACTORY_DEFINE)
            btSimpleFactory.setOnClickListener {
                val rouJiaMoStore = RoujiamoStore(SimpleRoujiaMoFactory()).apply {
                    sellRoujiamo("suan")
                    sellRoujiamo("tian")
                    sellRoujiamo("la")
                }
            }
            btFactoryMethod.setOnClickListener {
                val xianRoujiamoStore = XianRoujiamoStaore(XianSimpleRoujiamoFactory()).apply {
                    sellRoujiamo("suan")
                    sellRoujiamo("tian")
                    sellRoujiamo("la")
                }
            }
            btAbstractFactory.setOnClickListener {
                val xianRoujiamoTeSeStrore = XianRoujiamoTeSeStrore(XianSimpleRoujiaMoTeSeFacktory())
                    .apply { sellRoujiaMo("suan") }
            }

        }
    }
}